﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script src="lib/cookie/cookie.js"></script>
</head>
<body>
    <script>
        function getrequest() {
            var url = location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    var arr, reg = new RegExp("(^| )" + strs[i].split("=")[0] + "=([^;]*)(;|$)");
                    if (arr = strs[i].match(reg))
                        theRequest[strs[i].split("=")[0]] = unescape(arr[2]);
                    /* theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);*/
                }
            }
            return theRequest;
        }

        //进行将请求地址缓存下来
        function gethosttingadr() {
            //删除某个键值对
            localStorage.removeItem('hosttingaddr');
            //获取配置内容
            layui.jquery.ajax({
                url: "../jsconfig.json",
                async: false,
                type: "GET",
                dataType: "json",
                success: function (json) {
                    // 写入数据
                    localStorage.setItem('hosttingaddr', json.appsetting.hosttingaddr);
                }
            });
            var addr = localStorage.getItem('hosttingaddr');
            return addr;
        }
        layui.$(function () {
            var data ={
                Name: getrequest().name,
                IsVerifyPassword: false
            };
            removeCookie("userinfo");
            removeCookie("version");
            layui.$.ajax({
                type: "post",
                url: gethosttingadr() + '/api/UserAuthority/loginverify',
                data: JSON.stringify(data),
                success: function (da) {
                    setCookie('userinfo', da.user, 1);
                    setCookie('version', da.version, 1)
                    location.href = 'index.html'
                },
                error: function (xhr, textStatus, errorThrown) {
                    layer.msg("用户信息验证失败！", function () {
                        layui.$("input[name='username']").focus();
                    });
                }
            });
        });
    </script>
</body>
</html>